#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define uint unsigned int

#define YES cout << "YES" << '\n'
#define NO cout << "NO" << '\n'
#define endl '\n'
const int INF = 1e9;
const int MOD = 998244353;
using namespace std;

/*思考

*/

int w[105]={0};
int v[105]={0};
int dp[1005]={0};//dp[i][j]为容量为j时只拿前i捡物品的最大值；
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N,V;
    cin>>N>>V;
    for(int i=1;i<=N;i++){
        cin>>v[i]>>w[i];
    }
    for(int i=1;i<=N;i++){//
        for(int j=V;j>=v[i];j--){
            dp[j]=max(dp[j-v[i]]+w[i],dp[j]);
        }
    }
    cout<<dp[V];
    return 0;
}